package cn.uniqueinfo.dp.controller;

import cn.uniqueinfo.dp.controller.base.BaseController;
import cn.uniqueinfo.dp.service.IRoleService;
import cn.uniqueinfo.dp.vo.EasyUiTreeVO;
import cn.uniqueinfo.dp.vo.RoleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author:朱元勋
 * @mail:395910063@qq.com
 * @date:2019-01-24 11:32:14
 * @description:角色管理
 */
@Slf4j
@Controller
@RequestMapping(value = "/role")
public class RoleController extends BaseController<RoleVO> {
    private IRoleService service;

    public RoleController(IRoleService service) {
        this.service = service;
        this.baseService = service;
        this.ctlName = "role";
        this.tipName = "角色管理";
    }

    @GetMapping("/tree")
    @ResponseBody
    public List<EasyUiTreeVO> tree() {
        List<RoleVO> roleList = this.service.findAll(null);
        List<EasyUiTreeVO> list = new ArrayList<>();
        for (RoleVO roleVO : roleList) {
            EasyUiTreeVO treeVO = new EasyUiTreeVO();
            treeVO.setId(roleVO.getId());
            treeVO.setText(roleVO.getRoleDisplay());
            list.add(treeVO);
        }
        return list;
    }
}
